﻿using KELT.KELTObjects.ViewportObjectModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;

namespace KELT.Animation.Animation3D
{

    public class Rot2DAnimation : IAnimation
    {
        private Rotation3DAnimation rotateAniamtion1;
        private Rotation3DAnimation rotateAniamtion2;
        private Rotation3DAnimation rotateAniamtion3;

        public Rot2DAnimation()
        {

            rotateAniamtion1 = new Rotation3DAnimation();
            rotateAniamtion2 = new Rotation3DAnimation();
            rotateAniamtion3 = new Rotation3DAnimation();

        }

        public override void SetAnimation(Storyboard myStoryboard, ViewportObj obj)
        {
            animationName = "2D 회전";

            Vector3D vector3D = new Vector3D(0, 0, 1);

            //회전애니메이션설정
            rotateAniamtion1.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion1.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3));

            rotateAniamtion1.From = new AxisAngleRotation3D(vector3D, 0);
            rotateAniamtion1.By = new AxisAngleRotation3D(vector3D, 120);


            Storyboard.SetTargetName(rotateAniamtion1, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion1, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion1);



            //회전애니메이션설정
            rotateAniamtion2.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion2.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3 * 2));

            rotateAniamtion2.From = new AxisAngleRotation3D(vector3D, 120);
            rotateAniamtion2.To = new AxisAngleRotation3D(vector3D, 240);


            Storyboard.SetTargetName(rotateAniamtion2, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion2, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion2);



            //회전애니메이션설정
            rotateAniamtion3.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion3.BeginTime = TimeSpan.FromSeconds(startTime + (endTime - startTime));

            rotateAniamtion3.From = new AxisAngleRotation3D(vector3D, 240);
            rotateAniamtion3.To = new AxisAngleRotation3D(vector3D, 360);


            Storyboard.SetTargetName(rotateAniamtion3, AnimationInfo.ANIMATION_ROTATE + obj.getIndexNumber());
            Storyboard.SetTargetProperty(rotateAniamtion3, new PropertyPath(RotateTransform3D.RotationProperty));
            myStoryboard.Children.Add(rotateAniamtion3);

        }


        public override void changeAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(rotateAniamtion1);
            myStoryboard.Children.Remove(rotateAniamtion2);
            myStoryboard.Children.Remove(rotateAniamtion3);

            rotateAniamtion1.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion1.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3));

            rotateAniamtion2.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion2.BeginTime = TimeSpan.FromSeconds(startTime + ((endTime - startTime) / 3 * 2));

            rotateAniamtion3.Duration = TimeSpan.FromSeconds((endTime - startTime) / 3);
            rotateAniamtion3.BeginTime = TimeSpan.FromSeconds(startTime + (endTime - startTime));

            myStoryboard.Children.Add(rotateAniamtion1);
            myStoryboard.Children.Add(rotateAniamtion2);
            myStoryboard.Children.Add(rotateAniamtion3);
        }

        public override void deleteAnimation(Storyboard myStoryboard)
        {
            myStoryboard.Children.Remove(rotateAniamtion1);
            myStoryboard.Children.Remove(rotateAniamtion2);
            myStoryboard.Children.Remove(rotateAniamtion3);
        }
    }
}
